package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappProcessEmailEntity;
import com.infocollect.project.api.mapper.TappProcessEmailMapper;
import com.infocollect.project.api.service.ITappProcessEmailService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TappProcessemail)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:30
 */
@Service("tappProcessemailService")
public class TappProcessEmailServiceImpl extends ServiceImpl<TappProcessEmailMapper, TappProcessEmailEntity> implements ITappProcessEmailService {

    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappProcessEmailEntity queryById(Long fid) {
        return this.baseMapper.queryById(fid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TappProcessEmailEntity> queryAllByLimit(int offset, int limit) {
        return this.baseMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tappProcessemail 实例对象
     * @return 实例对象
     */
    @Override
    public TappProcessEmailEntity insert(TappProcessEmailEntity tappProcessemail) {
        this.baseMapper.insert(tappProcessemail);
        return tappProcessemail;
    }

    /**
     * 修改数据
     *
     * @param tappProcessemail 实例对象
     * @return 实例对象
     */
    @Override
    public TappProcessEmailEntity update(TappProcessEmailEntity tappProcessemail) {
        this.baseMapper.updateById(tappProcessemail);
        return this.queryById(tappProcessemail.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     * 查询多条数据
     * @menu 根据实体对象是否有值 进行查询
     * @return 对象列表
     */
    @Override
    public List<TappProcessEmailEntity> queryAll(TappProcessEmailEntity entity){
        return this.baseMapper.queryAll(entity) ;
    }

    @Override
    public  List<TappProcessEmailEntity> queryByProcessID(Long processid){
        QueryWrapper<TappProcessEmailEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("fprocessid",processid);
        return baseMapper.selectList(queryWrapper);
    }
    /**
     * 根据流程模板ID 删除流程的邮件通知
     * @param procesId
     * @return
     */
    @Override
    public boolean deleteByProcessID(Long procesId){
        return this.baseMapper.deleteByProcessID(procesId) > 0;
    }
}